Skip to content

NO TICKET: Handle NaN MP height and NULL history entries in legacy data transfers and property reads#542

Merged
jirhiker merged 2 commits intostagingfrom
kas-nan-mpheights
Feb 23, 2026
Merged

NO TICKET: Handle NaN MP height and NULL history entries in legacy data transfers and property reads#542
jirhiker merged 2 commits intostagingfrom
kas-nan-mpheights

Conversation

@ksmuczynski
Copy link
Copy Markdown
Contributor

@ksmuczynski ksmuczynski commented Feb 23, 2026

Why

This PR addresses the following problem / context:

  • NaN values in measuring_point_height and NULL history rows for measuring_point_description caused issues during data transfers and property calculations.

How

Implementation summary - the following was changed / added / removed:

  • Updated logic to ignore None values during property calculations.
  • Enhanced migration handling to persist NULL rows when MPHeight is missing or NaN, even when an estimate could be derived.
  • Maintained existing estimator-based behavior when valid MPHeight values are present.
  • Added a test case to verify correct handling of null measuring point history.

Notes

Any special considerations, workarounds, or follow-up work to note?

- Treat missing/NaN MPHeight as unknown and set to `None`
- Persist a NULL MeasuringPointHistory row whenever MPHeight is missing/NaN, even if an estimate could be derived.
- If MPHeight is present, existing estimator-based behavior remains.
- Updated logic to ignore `None` values for `measuring_point_height` and `measuring_point_description`.
- Added test to verify correct handling of null measuring point history.
@ksmuczynski ksmuczynski changed the title NO TICKET: Skip NULL measuring point history in legacy data transfers NO TICKET: Address NaN measuring point history in legacy data transfers Feb 23, 2026
@ksmuczynski ksmuczynski changed the title NO TICKET: Address NaN measuring point history in legacy data transfers NO TICKET: Handle NaN MP height and NULL history entries in legacy data transfers and property reads Feb 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses handling of NULL/NaN values in measuring point data during legacy data transfers. When MPHeight is NaN or missing in the source data, the system now skips estimation and inserts NULL values directly, ensuring complete well migration without unreliable estimator calls. The read path is hardened to skip NULL history entries and return the most recent non-NULL value.

Changes:

  • Modified transfer logic to detect NaN values and skip the measuring point estimator for those cases
  • Updated measuring_point_height and measuring_point_description properties to iterate through history and return first non-NULL value
  • Added test coverage for NULL history record handling

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
transfers/well_transfer.py Updated _build_well_payload to treat NaN MPHeight as None; refactored _add_histories to conditionally call estimator only for valid MPHeight values and persist NULL records otherwise
db/thing.py Modified measuring_point_height and measuring_point_description properties to skip NULL values in history and return most recent non-NULL value
tests/test_thing.py Added test to verify properties correctly skip NULL history entries and return older non-NULL values

Comment on lines +762 to +773
if not added_measuring_point:
raw_desc = getattr(row, "MeasuringPoint", None)
mp_desc = None if isna(raw_desc) else raw_desc
session.add(
MeasuringPointHistory(
thing_id=well.id,
measuring_point_height=None,
measuring_point_description=mp_desc,
start_date=datetime.now(tz=UTC).date(),
end_date=None,
)
)
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block that handles the fallback case when the estimator returns no results is duplicated from lines 735-745. Consider refactoring to eliminate this duplication. You could extract the logic for creating a NULL measuring point history record into a helper method or move this fallback outside the if-else block since both branches need it.

Copilot uses AI. Check for mistakes.
pass
if mpheight is None or isna(mpheight):
# Treat missing/NaN MPHeight as unknown during migration.
mpheight = None
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When MPHeight is None or NaN, the measuring point description should also be checked for NaN and converted to None before passing to CreateWell. If row.MeasuringPoint contains a pandas NaN value (float), it could fail Pydantic validation since measuring_point_description expects str | None, not a float. Consider adding: mpheight_description = None if isna(row.MeasuringPoint) else row.MeasuringPoint inside the if block for consistency with the handling in _add_histories (lines 735-736).

Suggested change
mpheight = None
mpheight = None
mpheight_description = (
None if isna(row.MeasuringPoint) else row.MeasuringPoint
)

Copilot uses AI. Check for mistakes.
@jirhiker jirhiker merged commit 7c0e920 into staging Feb 23, 2026
12 checks passed
@TylerAdamMartinez TylerAdamMartinez deleted the kas-nan-mpheights branch February 26, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle legacy MPHeight NaNs as NULLs (skip estimator) to ensure full well migration

3 participants